package fl.ass.service.api;


import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import fl.ass.facade.api.IAssTrailCarChannelApi;
import fl.ass.facade.condition.AssTrailCarChannelQC;
import fl.ass.facade.dto.AssTrailCarChannelDTO;
import fl.ass.service.service.IAssTrailCarChannelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zk
 * @create 2018-09-11 8:49
 * @desc
 **/
@Service
public class AssTrailCarChannelApi implements IAssTrailCarChannelApi {

    private static final Logger logger = LoggerFactory.getLogger(AssDealCarApi.class);

    @Autowired
    private IAssTrailCarChannelService assTrailCarChannelService;


    @Override
    public Pager searchListPage(Pager page) throws BaseException {
        if(null == page){
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
        }
        return this.assTrailCarChannelService.searchListPage(page);
    }

    @Override
    public boolean enAbleChannel(Long id, Integer isValidInt) throws BaseException {
        if(null == id){
            BaseLogUtils.newLogger("启用或禁用拖车渠道,主键参数为空").info();
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
        };
        return this.assTrailCarChannelService.enAbleChannel(id, isValidInt);
    }

    @Override
    public AssTrailCarChannelDTO selectById(Long id) throws BaseException {
        if(null == id){
            BaseLogUtils.newLogger("主键参数为空").info();
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
        };
        return this.assTrailCarChannelService.selectById(id);
    }

    @Override
    public Long add(AssTrailCarChannelDTO assTrailCarChannelDTO) throws BaseException {
        if(null == assTrailCarChannelDTO){
            BaseLogUtils.newLogger("assTrailCarChannelDTO 参数为空").info();
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
        };
        try {
            return this.assTrailCarChannelService.add(assTrailCarChannelDTO);
        } catch (BaseException e) {
            BaseLogUtils.newLogger("新增异常").setThrowable(e).info();
            throw new BaseException(e.getCode(),e.getMessage());
        }
    }

    @Override
    public boolean modify(AssTrailCarChannelDTO assTrailCarChannelDTO) throws BaseException {
        if(null == assTrailCarChannelDTO){
            BaseLogUtils.newLogger("assTrailCarChannelDTO 参数为空").info();
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
        };
        try {
            return this.assTrailCarChannelService.modify(assTrailCarChannelDTO);
        } catch (BaseException e) {
            BaseLogUtils.newLogger("修改异常").setThrowable(e).info();
            throw new BaseException(e.getCode(),e.getMessage());
        }
    }

    @Override
    public List<AssTrailCarChannelDTO> searchList(AssTrailCarChannelQC qc) throws BaseException {
        if(null == qc) return new ArrayList<AssTrailCarChannelDTO>();
        return this.assTrailCarChannelService.searchList(qc);
    }
}
